package club.itstudio.IContainer.controller.admin;

import club.itstudio.IContainer.annotation.AdminRequired;
import club.itstudio.IContainer.annotation.LoginRequired;
import club.itstudio.IContainer.entity.Container;
import club.itstudio.IContainer.service.ContainerService;
import club.itstudio.IContainer.util.Result;
import club.itstudio.IContainer.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/container")
public class ContainerController {

    private ContainerService containerService;

    @Autowired
    public void setContainerService(ContainerService containerService) {
        this.containerService = containerService;
    }

    @GetMapping("/list")
    @AdminRequired
    @LoginRequired
    public Result getContainerList(@RequestParam int page, @RequestParam int limit) {
        List<Container> containers = containerService.getByPage(page, limit);
        Integer containerCount = containerService.getContainerCount();
        Map<String, Object> data = new HashMap<>();
        data.put("total", containerCount);
        data.put("content", containers);
        return ResultUtil.success(data);
    }
}
